#include "time.h"
#include "time2.h"
#include <iostream>

void useTime();
void useTime2();
void initBasicTypes();
void initPod();
void initArray();

int main(int argc, char *argv[]) {
  std::cout << "==== ch01 p04 ====" << std::endl;
  printf("---- useTime() ----\n");
  useTime();
  printf("---- useTime2() ----\n");
  useTime2();
  printf("---- initBasicTypes() ----\n");
  initBasicTypes();
  printf("---- initPod() ----\n");
  initPod();
  printf("---- initArray() ----\n");
  return 0;
}

void useTime() {
  Time t;
  t.setYear(2024);
  t.addYear();
  printf("Year is %d\n", t.getYear());
}

void useTime2() {
  Time2 t;
  t.addYear();
  printf("Year is %d\n", t.getYear());
}

void initBasicTypes() {
  // 初始化为 0
  int a1{};
  // 初始化为任意值
  int a2{22};
  printf("a1 = %d, a2 = %d\n", a1, a2);
}

struct MyStruct {
  int age;
  char name[50];
  bool isMarried;
};

void initPod() {
  // 初始化为 0
  MyStruct s1{}; // 等价于 MyStruct s1 = {0, "", false};
  // 初始化为任意值
  MyStruct s2{25, "Alice", true};
  // 部分初始化
  MyStruct s3{25, "Bob"}; // 等价于 MyStruct s3 = {25, "Bob", false};
  printf("s1: Age is %d, Name is %s, isMarried is %d\n", s1.age, s1.name,
         s1.isMarried);
  printf("s2: Age is %d, Name is %s, isMarried is %d\n", s2.age, s2.name,
         s2.isMarried);
  printf("s3: Age is %d, Name is %s, isMarried is %d\n", s3.age, s3.name,
         s3.isMarried);
}

void initArray() {
  // 初始化为 0
  int a1[5]{};
  // 初始化为任意值
  int a2[5]{1, 2, 3, 4, 5};
  // 部分初始化
  int a3[5]{1, 2, 3}; // 等价于 int a3[5]{1, 2, 3, 0, 0};
}
